﻿@model Telerik.Web.Mvc.GridModel<BlogCommentModel>
@using Telerik.Web.Mvc.UI

@{
    var gridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSize;
    
    //page title
    ViewBag.Title = @T("Admin.ContentManagement.Blog.Comments").Text;
}
@{
    int? filterByBlogPostId = ViewBag.FilterByBlogPostId;
}
<div class="section-header">
    <div class="title">
        <img src="@Url.Content("~/Administration/Content/images/ico-content.png")" alt="" />
        @T("Admin.ContentManagement.Blog.Comments")
    </div>
    <div class="options">
    </div>
</div>
<table class="adminContent">
    <tr>
        <td>
            @(Html.Telerik().Grid<BlogCommentModel>(Model.Data)
                    .Name("comments-grid")
                    .DataKeys(x => {
                        x.Add(y => y.Id).RouteKey("Id");
                    })
                    .Columns(columns =>
                    {
                        columns.Bound(x => x.Id)
                            .Width(50);
                        columns.Bound(x => x.BlogPostTitle)
                            .Width(200)
                            .Template(x => Html.ActionLink(x.BlogPostTitle, "Edit", "Blog", new { id = x.BlogPostId }, new { }))
                            .ClientTemplate("<a href=\"" +  @Url.Content("~/Admin/Blog/Edit/") + "<#= BlogPostId #>\"><#= BlogPostTitle #></a>");
                        columns.Bound(x => x.CustomerId)
                            .Width(50)
                            .Template(x => Html.ActionLink(T("Admin.Common.View").Text, "Edit", "Customer", new { id = x.CustomerId }, new { }))
                            .ClientTemplate("<a href=\"" + @Url.Content("~/Admin/Customer/Edit/") + "<#= CustomerId #>\">" + T("Admin.Common.View").Text + "</a>");
                        columns.Bound(x => x.Comment)
                            .Width(350)
                            .Encoded(false)
                            .Centered();
                        columns.Bound(x => x.IpAddress)
                            .Width(100)
                            .Centered();
                        columns.Bound(x => x.CreatedOn)
                            .Width(100)
                            .Centered();
                        columns.Command(commands =>
                        {
                            commands.Delete();                            
                        }).Width(90);
                    })
                    .Pageable(settings => settings.Total(Model.Total).PageSize(gridPageSize).Position(GridPagerPosition.Both))
                    .DataBinding(dataBinding => {
                        var settingBuilder = dataBinding.Ajax();
                        if (filterByBlogPostId.HasValue)
                        {
                            settingBuilder = settingBuilder.Select("Comments", "Blog", new { filterByBlogPostId = filterByBlogPostId.Value });
                            settingBuilder = settingBuilder.Delete("CommentDelete", "Blog", new { filterByBlogPostId = filterByBlogPostId.Value });
                        }
                        else
                        {
                            settingBuilder = settingBuilder.Select("Comments", "Blog");
                            settingBuilder = settingBuilder.Delete("CommentDelete", "Blog");
                        }
                    })
                    .EnableCustomBinding(true))
        </td>
    </tr>
</table>
